package com.my.meitianbackup.utils;

import java.util.HashMap;

import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.my.meitianbackup.crawler.MogujieCrawler;
import com.my.meitianbackup.crawler.TaoKeZhuShouNewCrawler;
import com.my.meitianbackup.model._MappingKit;

public class BackupMain {
	
	public static void initDataBase() {
		PropKit.use("config.properties");
		C3p0Plugin c3p0Plugin = new C3p0Plugin("jdbc:mysql://121.42.158.63/meitian?characterEncoding=utf-8", "root",
				"ysyhl9T1");
		c3p0Plugin.start();
		ActiveRecordPlugin activeRecordPlugin = new ActiveRecordPlugin(c3p0Plugin);
		_MappingKit.mapping(activeRecordPlugin);
		activeRecordPlugin.start();
		System.out.println("init finish");
	}
	
	public static void main(String[] args) {
		initDataBase();
		//getTaobao();
		getMoogujie();
	}

	private static void getTaobao() {
		try {
			Long start = System.currentTimeMillis();
			ExcelUtil.readExcelWithTitle();
			Long excel = System.currentTimeMillis();
			
			
			TaoKeZhuShouNewCrawler taokeCrawler = new TaoKeZhuShouNewCrawler();
			taokeCrawler.runCrawler();
			Long crawler = System.currentTimeMillis();
			
			
			TaokeUtils.getImgs();
			Long imgs = System.currentTimeMillis();
			
			System.out.println("execl:"+ (excel-start));
			System.out.println("crawler:"+ (crawler-excel));
			System.out.println("imgs:"+ (imgs-crawler));
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	public static void getMoogujie() {
		Long start = System.currentTimeMillis();
		HashMap<String,Integer> map = MogujieCrawler.getMogujieList();
		
		Long end = System.currentTimeMillis();
		
		System.out.println("mogujie"+ (end-start));
		
		for(String s : map.keySet()) {
			Integer value = map.get(s);
			System.out.println(s + ": " + value);
		}
/*		Long time = System.currentTimeMillis()/1000L;
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
		String dateStr = sdf.format(date);
		for(int i=0; i<Constants.moguCatesSelectNums.length; i++) {
			Db.update("update mogujie set `publishDate` = ? where id in("
					+ "select t.id from (select * from mogujie where `campaignEndTime` >= ? and `publishDate` is null and cid = ? order by sale desc limit ?)as t)",dateStr,time,Constants.moguCateId[i],Constants.moguCatesSelectNums[i]);
			
		}*/
		
	}
}
